<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div th:if="${role.id}==1" class="card">
                <div class="card-body">
                   <div>权限：</div>
                    <!-- <form action="#!" method="post" class="row">-->
                    <select id="rolelist" th:value="${role1.id}">
                        <option value="2">管理员</option>
                        <option value="3">普通会员</option>
                    </select>
                    <div>状态：</div>
                    <select id="status" th:value="${user1.status}">
                        <option value="1">正常</option>
                        <option value="2">冻结</option>
                        <option value="3">删除</option>
                    </select>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="subfrom()">确认修改</button>
                    </div>
                </div>
                <!-- </form>-->
            </div>
            <div th:if="${role.id}==2" class="card">
                <div class="card-body">
                    <div>状态：</div>
                    <select id="status1" th:value="${user1.status}">
                        <option value="1">正常</option>
                        <option value="2">冻结</option>
                        <option value="3">删除</option>
                    </select>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="subfrom1()">确认修改</button>
                    </div>
                </div>
                <!-- </form>-->
            </div>
            <input type="hidden" id="uid"  th:value="${user1.id}">
        </div>
    </div>
</div>
<script th:inline="javascript">
    window.onload=function () {
        if([[${role.id}]]=='1'){
            obj = document.getElementById("rolelist");
            stut = document.getElementById("status");
            for(i=0;i<obj.length;i++){
                if(obj[i].value==[[${role1.id}]])
                    obj[i].selected = true;
            }
            for(i=0;i<stut.length;i++){
                if(stut[i].value==[[${user1.status}]])
                    stut[i].selected = true;
            }
        }else if ([[${role.id}]]=='2'){
            obj = document.getElementById("status1");
            for(i=0;i<obj.length;i++){
                if(obj[i].value==[[${user1.status}]])
                    obj[i].selected = true;
            }
        }

    }
</script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script>
<script type="text/javascript" src="/lib/js/jquery.min.js"></script>
<script type="text/javascript" src="/lib/js/bootstrap.min.js"></script>
<!--标签插件-->
<script src="/lib/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="/lib/js/main.min.js"></script>
<script>
    function subfrom() {
        $.ajax({
            url:"/user/modify?roleid="+$("#rolelist").val()+ "&status="+$("#status").val()+"&uid="+$("#uid").val(),
            type: 'POST',
            cache: false,
            data: {},//表单数据
            processData: false,
            contentType: false,
            success: function (rtn) {
                if (rtn.code ==0 ) {
                    alert("修改成功")　　//根据后端返回值,回显错误信息
                } else {
                    alert("修改失败")
                }
            }
        })
    }
    function subfrom1() {
        $.ajax({
            url:"/user/modify?status="+$("#status1").val()+"&uid="+$("#uid").val(),
            type: 'POST',
            cache: false,
            data: {},//表单数据
            processData: false,
            contentType: false,
            success: function (rtn) {
                if (rtn.code ==0 ) {
                    alert("修改成功")　　//根据后端返回值,回显错误信息
                } else {
                    alert("修改失败")
                }
            }
        })
    }
</script>
</body>
</html>